exoskeleton.models.base_model = Backbone.Model.extend({

  __fetchStatus: new exoskeleton.models.load_status,

  fetchStatus: function(){
    return this.__fetchStatus
  },

  parse: function(response){
    var data = _.isUndefined(response.data) ? response : response.data
    return data
  },

  fetch: function(options){
    var _this = this ;
    this.__fetchStatus = new exoskeleton.models.load_status()
    Backbone.Model.prototype.fetch.call(this,{
      success: function(model, response){
        _this.__fetchStatus.set_completed()
        _this.__fetchStatus.set_message(response.message)
        if(response.success){
          _this.__fetchStatus.set_successful()
          _this._original_attributes = _.clone(model.attributes);
          _this.trigger('fetch:successful', model, response.data, response.message)
        } else {
          _this.trigger('fetch:unsuccessful', model, response.data, response.message)
        }
        if(options && options.success){
          options.success(model, response)
        }
        _this.trigger('fetch:complete', model, response.data, response.message)
      },
      error: function(model, response) {
        _this.__fetchStatus.set_completed()
        _this.__fetchStatus.set_message(response.message)
        _this.__fetchStatus.set_system_error()
        _this.trigger('fetch:error', model, response.data, response.message)
        if(options && options.error){
          options.error(model, response)
        }
        _this.trigger('fetch:complete', model, response.data, response.message)
      }
    })
  },


})